home *** CD-ROM | disk | FTP | other *** search
- /*
- File: EnableSelfSendSample.c
- By: Rich Kubota
- Developer Technical Support
-
- Purpose: Demonstrate the use of the OTOptionManagement call to tell an AppleTalk
- endpoint to enable/disable the SelfSend option.
-
- change history
- 1/8/98 - observed that an option management call to set self send hung under
- OT 1.2. Modified code so that if OT 1.2 or earlier is detected, then use the
- classic AppleTalk call - PSetSelfSend to set self send feature. Also note
- that if the endpoint is async, the same call to PSetSelfSend is made.
- */
-
- #include "OpenTransport.h" // open transport files
- #include "OpenTptAppletalk.h"
- #include "AppleTalk.h"
-
- #define kOTVersion120 0x01208000
-
- extern OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend);
-
-
- /*
- Sample function to enable/disable the SelfSend option for
- an AppleTalk endpoint. This function also demonstrates the
- use of the OTOptionManagement call.
-
-
- Unless explicitely defined by XTI, all Open Transport options
- use a kOTFourByteOptionSize buffer.
-
- Input
- EndpointRef ep - endpoint on which to set SelfSend option on
- long enableSelfSend - 1L - option on, 0L - option off
-
- Return: kOTNoError indicates that the option was successfully negotiated
- OSStatus is an error if < 0, otherwise, the status field is
- returned and is > 0.
-
- */
- OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend)
-
- {
- UInt8 buf[kOTFourByteOptionSize]; // define buffer for fourByte Option size
- TOption* opt; // option ptr to make items easier to access
- TOptMgmt req;
- TOptMgmt ret;
- long version;
- OSStatus err;
- SetSelfparms pb;
- Boolean usePB = false;
-
- err = Gestalt('otvr', (long*)&version);
- if (version <= kOTVersion120)
- usePB = true;
-
- if (OTIsSynchronous(ep) == false) // check whether ep sync or not
- usePB = true;
-
- if (usePB == true)
- {
- pb.newSelfFlag = enableSelfSend != 0 ? true : false; /* set self send option */
- err = PSetSelfSend((MPPPBPtr) &pb, false);
-
- }
- else
- {
- opt = (TOption*)buf; // set option ptr to buffer
- req.opt.buf = buf;
- req.opt.len = sizeof(buf);
- req.flags = T_NEGOTIATE; // negotiate for SelfSend option
-
- ret.opt.buf = buf;
- ret.opt.maxlen = kOTFourByteOptionSize;
-
- opt->level = ATK_DDP; // dealing with DDP
- opt->name = OPT_SELFSEND;
- opt->len = kOTFourByteOptionSize;
- opt->status = 0;
- *(UInt32*)opt->value = enableSelfSend; // set the desired option level, true or false
-
- DebugStr("\p About to call Option management");
- err = OTOptionManagement(ep, &req, &ret);
-
- // if no error then return the option status value
- if (err == kOTNoError)
- {
- if (opt->status != T_SUCCESS)
- err = opt->status;
- else
- err = kOTNoError;
- }
- }
-
- return err;
- }
-